<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../layui/css/layui.css">
</head>

<body>
	<form class="layui-form">
		<div class="layui-form-item">
			<label class="layui-form-label">姓名</label>
			<div class="layui-input-inline">
				<input type="text" name="name" placeholder="输入姓名" required
					lay-verify="required" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">身份证号</label>
			<div class="layui-input-inline">
				<input type="text" name="idcard" placeholder="输入身份证号" required
					lay-verify="required" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">电话号码</label>
			<div class="layui-input-inline">
				<input type="text" name="phone" placeholder="输入电话号码" required
					lay-verify="required" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
			    <input type="hidden" name="id">
				<button class="layui-btn" lay-submit lay-filter="user-edit">立即提交</button>
			</div>
		</div>
	</form>
	<script src="../layui/layui.js"></script>
	<script>
		layui.use([ 'form' ], function() {
			var form = layui.form,
			$=layui.$;
			var user=JSON.parse(sessionStorage.getItem('user'));
			$("input[name='id']").val(user.id);
			$("input[name='name']").val(user.name);
			$("input[name='idcard']").val(user.idcard);
			$("input[name='phone']").val(user.phone);
			form.on('submit(user-edit)', function(data) {
				$.ajax({
					url : '/api/user/edit',
					data : data.field,
					type : 'post',
					dataType : 'json',
					success : function(result) {
						if(result.code>0){
							parent.layer.msg('编辑成功');
							parent.layer.closeAll('iframe');
						}
						 else {
							layer.msg(result.msg);
						}
					},
					error : function() {
						layer.msg('请求失败');
					}
				});
				return false;
			});
		});
	</script>
</body>
</html>